package com.yunyao.dao.service.act.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunyao.dao.mapper.ActReProcdefMapper;
import com.yunyao.dao.model.ActReProcdef;
import com.yunyao.dao.service.act.IActReProcdefService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xingjishuai
 * @since 2024-07-02
 */
@Service
public class ActReProcdefServiceImpl extends ServiceImpl<ActReProcdefMapper, ActReProcdef> implements IActReProcdefService {

    /**
     * 根据部署ID获取流程定义
     *
     * @param deploymentId 部署ID
     * @return 如果找到对应的流程定义，则返回流程定义对象；如果找不到，返回null
     */
    @Override
    public ActReProcdef getByDeploymentId(String deploymentId) {
        // 检查部署ID是否为空或仅包含空白字符，如果是，则直接返回null
        if (StringUtils.isBlank(deploymentId)) {
            return null;
        }

        // 使用Lambda表达式创建查询包装器，设置查询条件为指定的部署ID
        LambdaQueryWrapper<ActReProcdef> wrapper =
                new LambdaQueryWrapper<ActReProcdef>()
                        .eq(ActReProcdef::getDeploymentId, deploymentId);

        // 使用查询包装器执行查询，获取并返回第一个匹配的流程定义
        return getOne(wrapper);
    }
}
